//
//  ShopTableViewCell.m
//  Liuhe
//
//  Created by zr on 2018/8/9.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "ShopTableViewCell.h"

@interface ShopTableViewCell ()

@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, strong)UIImageView * leftImageView;
@property (nonatomic, weak)UILabel * telLabel;
@property (nonatomic, weak)UILabel * contentLabel;
@property (nonatomic, weak)UILabel * companyLabel;
@property (nonatomic, weak)UIView * lineView;

@end


@implementation ShopTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}


-(void)setModel:(ShopModel *)model{
    
    _model = model;
    
    NSURL * url = [NSURL URLWithString:model.images];
    [self.leftImageView sd_setImageWithURL:url];
    
    self.telLabel.text = model.mobile;
    self.companyLabel.text = model.name;
    self.titleLabel.text = model.title;
    self.contentLabel.text = model.content;
}


- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = WHITE_COLOR;
    
    
    UIImageView * leftImageView = [UIImageView new];
    
    leftImageView.backgroundColor = [UIColor blueColor];
    
    self.leftImageView = leftImageView;
    
    [self.contentView addSubview:self.leftImageView];
    
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.text = @"中原六仔网投平台出租";
    titleLabel.textColor = BLACK_COLOR;
    titleLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    
    self.titleLabel = titleLabel;
    
    [self.contentView addSubview:self.titleLabel];

    
    UILabel * telLabel = [UILabel new];
    
    telLabel.text = @"12345685249";
    telLabel.textColor = [UIColor redColor];
    telLabel.font = [UIFont systemFontOfSize:16 * SCREENH6];
    telLabel.textAlignment = NSTextAlignmentRight;
    
    self.telLabel = telLabel;
    
    [self.contentView addSubview:self.telLabel];
    
    
    UILabel * contentLabel = [UILabel new];
    
    contentLabel.text = @"12345685249";
    contentLabel.textColor = ColorWithRGB(0x999999);
    contentLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    self.contentLabel = contentLabel;
    
    [self.contentView addSubview:self.contentLabel];
    
    
    UILabel * companyLabel = [UILabel new];
    
    companyLabel.text = @"12345685249";
    companyLabel.textColor = ColorWithRGB(0x999999);
    companyLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    self.companyLabel = companyLabel;
    
    [self.contentView addSubview:self.companyLabel];
    
    
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xe6e6e6);
    
    self.lineView = lineView;
    
    [self.contentView addSubview:self.lineView];
}


- (void)layoutSubviews{
    
    [self.leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.leading.mas_equalTo(self.contentView).offset(15 * SCREENH6);
        make.width.mas_equalTo(87 * SCREENH6);
        make.height.mas_equalTo(63 * SCREENH6);
    }];
    
    [self.telLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.contentView).offset(-15 * SCREENH6);
        make.top.mas_equalTo(self.leftImageView);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.telLabel);
        make.leading.mas_equalTo(self.leftImageView.mas_trailing).offset(10 * SCREENH6);
        make.trailing.mas_equalTo(self.telLabel.mas_leading);
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.titleLabel);
        make.trailing.mas_equalTo(self.telLabel);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.companyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.contentLabel);
        make.top.mas_equalTo(self.contentLabel.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.contentView);
        make.height.mas_equalTo(1 * SCREENH6);
        make.bottom.mas_equalTo(self.contentView);
    }];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
